package com.aikg.kgrag_java.service;

import com.aikg.kgrag_java.common.Result;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
import co.elastic.clients.elasticsearch.indices.GetIndexResponse;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import co.elastic.clients.util.ObjectBuilder;
import com.aikg.kgrag_java.pojo.entity.IndexDocument;
import org.springframework.stereotype.Service;

import java.util.function.Function;

import java.io.IOException;

@Service
public interface IndexService {
    /**
     * 新建指定名称的索引
     *
     * @param name
     * @return
     * @throws IOException
     */
    Result addIndex(String name) throws IOException;

    /**
     * 检查指定名称的索引是否存在
     * @param name
     * @return
     * @throws IOException
     */
    boolean indexExists(String name) throws IOException;

    /**
     * 删除指定索引
     *
     * @param name
     * @return
     * @throws IOException
     */
    Result delIndex(String name) throws IOException;

    /**
     * 创建索引，指定setting和mapping
     *
     * @param name      索引名称
     * @param settingFn 索引参数
     * @param mappingFn 索引结构
     * @return
     * @throws IOException
     */
    boolean create(String name,
                   Function<IndexSettings.Builder, ObjectBuilder<IndexSettings>> settingFn,
                   Function<TypeMapping.Builder, ObjectBuilder<TypeMapping>> mappingFn) throws IOException;

    /**
     * 查询索引详情
     *
     * @param name
     * @return
     * @throws IOException
     */
    GetIndexResponse getIndexDetail(String name) throws IOException;



    public boolean insertDocument(String indexName, String id, IndexDocument document) throws IOException;
}
